import store from '@/store'
// 导入axios
import axios from 'axios'
// 创建 axios实例(也就是克隆一份axios叫做request)
const request = axios.create({
  baseURL: 'http://interview-api-t.itheima.net',
  timeout: 5000
})
// 添加请求拦截器
request.interceptors.request.use(
  config => {
    config.headers.Authorization = 'Bearer ' + store.state.user.token
    return config
  },
  error => Promise.reject(error)
)
// 添加响应拦截器
request.interceptors.response.use(
  (response) => response.data,
  (error) => {
    return Promise.reject(error)
  }
)
// 导出配置好的 axios也就是request
export default request
